﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Qcy.Jshj.Web.Helpers;
using Qcy.Jshj.Web.Models;

namespace Qcy.Jshj.Web.Controllers
{
    public class HomeController : Controller
    {
        public void Language(string language, string returnUrl)
        {
            var lang = LanguageHelper.GetLanguage();
            Enum.TryParse<Language>(language, out lang);
            LanguageHelper.SetLanguage(lang);
            Response.Redirect(returnUrl);
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult News(int id = 0)
        {
            var model = DataHelper.GetArticle(id);
            return View(model);
        }

        /// <summary>
        /// 产品
        /// </summary>
        /// <param name="id">产品分类Id</param>
        public ActionResult Products(int id = 0, int cate = 0, int page = 1, int pageSize = 8)
        {
            var model = new ProductsModel(id, cate, page, pageSize);

            return View(model);
        }

        /// <summary>
        /// 关于我们
        /// </summary>
        public ActionResult About(int id = 0)
        {
            var model = DataHelper.CompanyInfo(id, Models.CompanyInfoType.About);
            if (string.Equals(model.Title, "公司简介", StringComparison.InvariantCultureIgnoreCase) || string.Equals(model.Title, "About Us", StringComparison.InvariantCultureIgnoreCase))
                return View("AboutUs", model);
            return View(model);
        }

        /// <summary>
        /// 质量控制
        /// </summary>
        public ActionResult Quality(int id = 0)
        {
            var model = DataHelper.CompanyInfo(id, Models.CompanyInfoType.Quality);
            return View(model);
        }

        /// <summary>
        /// 服务支持
        /// </summary>
        public ActionResult Service(int id = 0)
        {
            var model = DataHelper.CompanyInfo(id, Models.CompanyInfoType.Service);
            return View(model);
        }

        /// <summary>
        /// 订单联系
        /// </summary>
        public ActionResult Order(int id = 0)
        {
            var model = DataHelper.CompanyInfo(id, Models.CompanyInfoType.Order);
            return View(model);
        }

        /// <summary>
        /// 在线订单
        /// </summary>
        /// <returns></returns>
        public ActionResult OnLineOrder()
        {
            return View();
        }

        [HttpPost]
        public JsonResult OnlineOrder(Qcy.Jshj.Web.Models.Order order)
        {
            order.CreationDate = DateTime.Now;
            DataHelper.AddOrder(order);

            return Json(new { result = true }, "text/html");
        }
    }
}
